<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>fake</title>
    <link rel="stylesheet" href="#">
    <style>
        *{
        padding: 0;
        margin: 0;
    }
    .warrpt{
        height: 535px;
        width: 1200px;
        position: relative;
        margin: 0 auto;
        
    }
    .warrpt img{
        position: absolute;
        transition: all .8s;
    }
    .warrpt ul{
        position: absolute;
        left: 568px;
        bottom: 23px;

    }
    .warrpt ul li{
        list-style: none;
        width: 12px;
        height: 12px;
        background: #dddddd;
        float: left;
        border-radius: 50%;
        margin-right: 8px;
        cursor: pointer;
    }
    .warrpt .btn{
        position: absolute;
        width: 40px;
        height: 65px;
        opacity: 0.5;
        top: 235px;
        display: none;
    }
    .warrpt:hover .btn {
            display: block;
        }
    #gopre {
        left: 0;
    }
    #gonext {
        right: 0;
    }
</style>
</head>

<body>
    <div class="warrpt" onmouseover="mOver(this)" onmouseout="mOut(this)" >
        <img src="img/0.jpg" alt="图1" style="display: block">
        <img src="img/1.jpg" alt="图2">
        <img src="img/2.jpg" alt="图3">
        <ul>
            <li data-index='0'></li>
            <li data-index='1'></li>
            <li data-index='2'></li>
        </ul>
        <button type="button" class="btn" id="gopre"> < </button>
        <button type="button" class="btn" id="gonext">> </button>
    </div>



    
    <script type="text/javascript">
        var warrpt = document.getElementsByClassName('warrpt')[0];
        var img0 = warrpt.getElementsByTagName('img');
        var li0 = warrpt.getElementsByTagName('li');
        var goNextBtn = document.getElementById('gonext');
        var goPreBtn = document.getElementById('gopre');
        var c = 0;

        var clearC = function () {
            for (var i = 0; i < img0.length; i++) {
                img0[i].style.display = 'none';
                li0[i].style.background = '#dddddd';
                img0[i].style.opacity = '0';
            }

        }
        var golunbo = function () {

            clearC();

            img0[c].style.display = "block";
            li0[c].style.background = '#A10000';
            img0[c].style.opacity = '1';

        }


        var points;
        function play(){
            points= setInterval(function () {
            c++;
            if (c == 3) {
                c = 0;
            }
            golunbo();
        }, 1000)
        }
        play();

        var goNext = function () {
            if (c < 2) {
                c++;
            } else {
                c = 0;
            }
            golunbo();

        }
        var goPre = function () {
            if (c == 0) {
                c = 2;
            } else {
                c--;
            }
            golunbo();
        }
        goNextBtn.addEventListener('click', function () {
            goNext();
           
        })
        goPreBtn.addEventListener('click', function () {
            goPre();
           
        })
        for (var i = 0; i < li0.length; i++) {
            li0[i].addEventListener('click', function () {
                var li0dian = this.getAttribute('data-index');
                c = li0dian;
                golunbo();
               
            })
        }
       
       function stop(){
             clearInterval(points);
       }
       warrpt.onmouseover =stop;
       warrpt.onmouseout =play;
    </script>
</body>

</html>